﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;

namespace Zephyris_Space_Mercs_Server
{
    class DBManager
    {
        private static MySqlConnection dbConnection = new MySqlConnection();

        public static ErrorClass connectDB(string username, string password, string server, string database)
        {
            ErrorClass errorClass = new ErrorClass();
            errorClass.errorStatus = false;
            errorClass.errorMessage = "DB Connection OK";

            dbConnection.ConnectionString = "SERVER=" + server + ";" +
                                        "DATABASE=" + database + ";" +
                                        "USER NAME=" + username + ";" +
                                       "PASSWORD=" + password + ";" +
                                       "POOLING=false;";
            try
            {
                dbConnection.Open();
            }
            catch (Exception ex)
            {
                errorClass.errorStatus = true;
                errorClass.errorMessage = ex.Message;
            }

            return errorClass;
            
        }



        private static bool Validator(string input)
        {
            string textVal;

            textVal = input.ToUpper();

            string[] strDirtyQuery = { "xp_", ";", "--", "<", ">", "=", "==", "'", "script", "iframe", "delete", "drop", "exec", "and", "or", "select", "where" };

            foreach (string token in strDirtyQuery)
            {
                if (textVal.IndexOf(token.ToUpper()) != -1)
                {
                    return false;
                }
            }

            return true;
        }
    }
}
